package com.lib.common.helper.arouter;

import android.net.Uri;
import android.text.TextUtils;

import com.lib.framework.utils.StringUtil;



/**
 * Created by Zhangjiaxing on 2019/1/11.
 * If there are any problems, please
 * send email to kevin.zhang@xiangwushuo.com
 *
 * @descrpition
 **/
public class UrlWrapper {
    private static final String PRE_URL = "http://xiangwushuo.com";
    private String path;
    private Uri uri = Uri.EMPTY;

    public UrlWrapper(String path) {
        this.path = path;
        if (!TextUtils.isEmpty(path)) {
            if (!isHttp()) {
                uri = StringUtil.parseUri(PRE_URL + this.path);
            } else {
                uri = StringUtil.parseUri(path);
            }
        }
    }

    public UrlWrapper(Uri uri) {
        this.uri = uri;
        path = uri.toString();
    }

    private boolean isHttp() {
        return path.startsWith("http") || path.startsWith("https");
    }

    public String getPath() {
        return path;
    }

    public Uri getUri() {
        return uri;
    }

    public boolean isValid() {
        return !TextUtils.isEmpty(path) && path != null;
    }
}
